import db from "lodash";

export default {
  data() {
    return {
      timer: null,
      timer1: null,
      num: 0,
      name: "",
      listName: ""
    };
  },
  created() {
    console.log(this, "this");
  },
  methods: {
    suspend() {
      clearInterval(this.timer);
      clearTimeout(this.timer1);
    },
    begin() {
      this.timer = setInterval(this.scroll, 2000);
      let c, d, e;
      this.timer1 = setTimeout(() => {
        if (this.num) {
          e = this.num.toString();
          c = e.indexOf(".");
          d = e.slice(c + 1, c + 2);
          if (d >= 5) this.num = Math.ceil(this.num);
          this.num = Math.floor(this.num);
          // this.$refs.scoll.scrollTop = 37 * this.num;
          for (let i = 0; i < this.num; i++) {
            this[this.listName].push(this[this.listName][0]);
            this[this.listName].shift();
          }
          this.$refs[this.name].scrollTop = 0;
        }
      }, 500);
    },
    scollDb: db.debounce(function(name, listName, num) {
      this.num = this.$refs[name].scrollTop / num;
      this.name = name;
      this.listName = listName;
    }, 400)
  }
};
